layui.use(['table','laydate','form'], function() {
    var table = layui.table;
    var laydate = layui.laydate;
    var form = layui.form;

    form.on('submit(*)',function (d){
        //保存订单和学生数据
        var classId = $("#classId").val()

        if (classId != ''){
            d.field.classesId = classId
            //发送ajax添加订单
            $.ajax({
                type:'post',
                url:'/addDocument',
                data:d.field,
                dataType:'json',
                success:function (res){
                    if (res.state == '200'){
                        layer.msg('添加订单信息成功', {time: 1500, icon: 6}, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.reload(); //刷新父页面
                            parent.layer.close(index);
                        })
                    }else {
                        layer.msg('添加订单信息失败', {time: 1000, icon: 5}, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        })
                    }
                },
                error:function (e){
                    console.log('请求失败')
                }

            })
        }else {
            // 发送ajax添加订单分类和订单
            d.field.classId = 0
            $.ajax({
                type:'post',
                url:'/addClassDocumentAndDocument',
                data:d.field,
                dataType:'json',
                success:function (res){
                    if (res.state == '200'){
                        layer.msg('添加订单分类和订单信息成功', {time: 1500, icon: 6}, function (index) {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.reload(); //刷新父页面
                            parent.layer.close(index);
                        })
                    }else {
                        layer.msg('添加订单分类和订单信息失败', {time: 1000, icon: 5}, function (index) {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        })
                    }
                },
                error:function (e){
                    console.log('请求失败')
                }

            })
        }
    })

    //重置input输入框的内容
    form.on('submit(cz)',function (d){
        $("[name=documentAnnul]").val("0.00")
        $("[name=documentAdditionMoney]").val("0.00")
        $("[name=documentRemark]").val("请输入订单备注")
        $("[name=documentSchoolTerm]").val("    - - - -  ")
        $("[name=documnentCharge]").val("学费")
        $("[name=documentMoney]").val("0000.00")
        $("[name=documentRecevied]").val('0000.00')
    })
})

//获取当前时间
var myDate = new Date();
//获取当前时间戳
var timestamp = Date.parse(myDate);
//当做订单编号
$("#dj").text(timestamp)
$("[name=documentId]").val(timestamp)
//获取完整的年份(4位)
var year = myDate.getFullYear();
//设置给订单分类日期
$("[name=documentYear]").val(year)
//学号：
var id = localStorage.getItem("studentId")
$("[name=classStudentId]").val(id)



